package com.sckj.springboot.service;

import com.sckj.springboot.entity.User;
import com.sckj.springboot.event.MyEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserService {

    /**
     * 获取用户信息
     */
    public User getUser(){
        return new User(1,"张三","kncks");
    }

    @Resource
    private ApplicationContext applicationContext;

    /**
     * 发布事件
     */
    public User getUser2(){
        User user = new User(1,"zhang","123456");
        //发布事件
        MyEvent event = new MyEvent(this,user);
        applicationContext.publishEvent(event);
        return user;
    }
}
